<?php
header( "Content-Type: text/html; Charset=utf-8" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );

include("../include/init.php");
//メンバー削除
if($_POST["mode"] == "delete"){
	try{
		//カンマ区切り
		$pieces = explode(",", $_POST['screen_name']);
		
		//一つずつ削除する
		foreach($pieces as $del_user){
			$lists_Members_Destroy = $twitter->post_listsMembersDestroy(array("slug" => "test", "owner_screen_name" => "kr205","screen_name" => $del_user));
		}
		header("Location: ./twitter_Contents_List.php");
	//削除するユーザーが選択されていない場合。
	}catch(Exception $e){
		$del_error = true;
	}
}

//指定したTwitterのユーザーの情報を取得
if(isset($_POST["Account"])){
	
	$account = $_POST["Account"];
	$params = array();
	$params["screen_name"] = $account;

	$params_lcon = array();
	$params_lcon["profile_image_url_https"] = $account;

	//usersShow ユーザ情報取得
	try{
		$test = $twitter->get_usersShow($params);
		$info = $test->response;


		//リストにメンバー追加
		if($_POST["Registration"] != ""){
			$lists_Members_Create = $twitter->post_listsMembersCreate(array("slug" => "test", "owner_screen_name" => "kr205","screen_name" => $info["screen_name"]));
			header("Location: ./twitter_Contents_List.php");
		}
	//ユーザーが存在しない場合	
	}catch(Exception $e){
		$userShow_error = true;
	}

}else{
	echo '
	<form action="" method="post">
	';
}
?>

<!DOCTYPE HTML>
<html lang="ja-JP">
	<head>
		<meta charset="utf-8">
		<title>リスト内アカウント</title>
		<style>
			.user_box div,image{
				float:left;
			}
			.user_box{
				padding: 10px;
			}
		</style>
		<script>

function del(){
		if (window.confirm("削除してもよろしいですか？")) {

			var obj_chk = document.getElementsByClassName("chk_del");
			var obj_name = document.getElementsByClassName("user_screen_name");
			var length = obj_chk.length
			var names = '';

			if(length == 0){
				return;
			}

			for(i=0; i<length; i++){
				if(obj_chk[i].checked){
					if(names != ""){
						names = names + ",";
					}
					names = names + obj_name[i].innerHTML;
				}
			}
			document.getElementById("screen_name").value = names;
			document.getElementById("mode").value = "delete";
		}
}
		</script>
	</head>
<body>


</body>
</html>


